package com.tr.rentcar.controller.home;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.tr.rentcar.model.bean.Cars;
import com.tr.rentcar.model.bean.Discount;
import com.tr.rentcar.model.bean.Employee;
import com.tr.rentcar.model.bean.PPT;
import com.tr.rentcar.model.bean.Place;
import com.tr.rentcar.model.bean.PlaceStore;
import com.tr.rentcar.model.dao.CarInfoDao;
import com.tr.rentcar.model.dao.DiscountDao;
import com.tr.rentcar.model.dao.EmployeeDao;
import com.tr.rentcar.model.dao.PPTdao;
import com.tr.rentcar.model.dao.PlaceDao;

/**
 * Servlet 
 */
@WebServlet("/home")
public class HomeController extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		DiscountDao ud = new DiscountDao();
		EmployeeDao ed=new EmployeeDao();
		CarInfoDao cd=new CarInfoDao();
		PPTdao ppt=new PPTdao();
		try {
			List<PPT> plist = ppt.getAll();
			request.setAttribute("plist", plist);
			//获取司机和活动中心信息
			List<Discount> list = ud.findThree();
			request.setAttribute("list", list);
			List<Employee> elist=ed.findAll();
			request.setAttribute("elist", elist);
			//精品车辆信息
			List<Cars> jpclist=cd.jingPin();
			request.setAttribute("jpclist", jpclist);
			//新品车辆信息
			List<Cars> xpclist=cd.xingpin();
			request.setAttribute("xpclist", xpclist);
			//热销车辆信息
			List<Cars> rxclist=cd.rexiao();
			request.setAttribute("rxclist", rxclist);
			//门店
			List<Place> placeList=new PlaceDao().getAll();
			request.setAttribute("place", placeList);
			List<PlaceStore> psList=new PlaceDao().getAllByid("1");
			request.setAttribute("placestore", psList);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		request.getRequestDispatcher("WEB-INF/jsp/home.jsp").forward(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
